package br.unesp.rc.rafaelt.resources;

/**
 * http://dafionsoftware.blogspot.com.br/2011/05/how-to-call-jersey-restful-service-from.html
 */

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import br.unesp.rc.rafaelt.business.services.StudentServices;
import br.unesp.rc.rafaelt.business.to.StudentTO;

@Component
@Path("/student")
public class StudentResource {

	@Autowired
	private StudentServices studentServices;
	
	@PersistenceContext
	private EntityManager em;

	@GET
	@Path("{id:[0-9]+}")
	@Produces({ MediaType.APPLICATION_JSON })
	public StudentTO findById(@PathParam("id") final Long id) {
		StudentTO studentTO = studentServices.findById(1L);
	
		//String studentTO = "Rafael";
		
		return studentTO;
	}
	
	/*@GET
	@Produces({ MediaType.APPLICATION_JSON })
	public Response findAll() {
		StudentListTO studentList = studentServices.findAll();
		
		return Response.ok(studentList).build();
	}	*/
	
    /*public List<Student> findAll() {
        CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
        cq.select(cq.from(Student.class));
        return getEntityManager().createQuery(cq).getResultList();
    }*/
    
    /*protected EntityManager getEntityManager() {
        return em;
    }*/

}